package models.ru.paralainer.chat.server.dao.impl;

import java.util.Date;
import java.util.List;

import javax.persistence.Query;

import models.ru.paralainer.chat.server.dao.MessageDAO;
import models.ru.paralainer.chat.server.domain.Message;
import play.db.jpa.JPA;

/**
 * User: stalov
 * Date: 22.05.12
 * Time: 14:16
 */
public class MessageDAOImpl extends GenericDAOImpl<Message> implements MessageDAO {
    
    public List<Message> getAll(){
        Query query =
                JPA.em().createNamedQuery("Message.findOlder");
        query.setParameter("date", new Date(0L));
        return query.getResultList();
    }

    @Override
    public List<Message> getOlder(Date date){
        Query query = JPA.em().createNamedQuery("Message.findOlder");
        query.setParameter("date", date);
        return query.getResultList();
    }

    @Override
    public List<Message> getOlderByMessageId(Long id){
        Query query = JPA.em().createNamedQuery("Message.findOlderByMessageId");
        query.setParameter("id", id);
        return query.getResultList();
    }

}
